using System;
using System.Collections;

namespace Evaluant.Uss.Commands
{
	[Serializable]
	public abstract class Command : IComparable
	{
		public Command(string parentId)
		{
			_ParentId = parentId;
		}

		protected string _ParentId;

		public string ParentId 
		{
			get { return _ParentId; }
		}

        protected string clientId;

        public string ClientId
        {
            get { return clientId; }
            set { clientId = value; }
        }


		public abstract void Accept(ICommandProcessor processor);

		public virtual void UpdateIds(Hashtable newIds)
		{
			if(newIds.Contains(ParentId))
				_ParentId = (string)newIds[ParentId];
		}

        protected bool ignoreMetadata = false;

        /// <summary>
        /// Gets or sets a value indicating whether to ignore metadata.
        /// </summary>
        /// <value><c>true</c> to ignore metadata; otherwise, <c>false</c>.</value>
        public bool IgnoreMetadata
        {
            get { return ignoreMetadata; }
            set { ignoreMetadata = value; }
        }

        protected int _ProcessOrder;

        /// <summary>
        /// Gets the process order.
        /// </summary>
        /// <value>The process order.</value>
        public int ProcessOrder
        {
            get { return _ProcessOrder; }
        }

		#region Membres de IComparable

		public int CompareTo(object obj)
		{
			Command c = obj as Command;
			
			if(c != null)
				return ProcessOrder.CompareTo(((Command)obj).ProcessOrder);
			else
				throw new ArgumentException("The object must be a Command");
		}

		#endregion
	}
}
